{% extends "templates/atnet_base.html" %}

{% block csslink %}
		{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	var wasAction = false;
	
	$('#invoices').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
            "sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
        },
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('vie_invoice', imm_id=immeuble.key().id(), command='list_4payments_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(6)', nRow).html('<a href="javascript:void(0);" id="' + aData[6] + '">{{ _("Payer") }}</a>');
		},
	});

	$('#invoices tbody tr a').live('click', function(e) {
		$(this).LaunchPopup(
			{
				TableId: '#invoices, #payments',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('vie_payments', imm_id=immeuble.key().id(), command='add') }}" + e.target.id + "/",
				Mode: 'add',
				Title: '{{ _("Add payment") }}'
			}
		)
	});

	$('#payments').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
            "sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
        },
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('vie_payments', imm_id=immeuble.key().id(), command='list_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(6)', nRow).html('<a href="javascript:void(0);" id="' + aData[6] + '">{{ _("Approve") }}</a>');
		},
	});
	
	
	$('#payments tbody tr a').live('click', function(e) {
		$(this).LaunchPopup(
			{
				TableId: '#invoices, #payments',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('vie_payments', imm_id=immeuble.key().id(), command='approve') }}" + e.target.id + "/",
				Mode: 'edit',
				Title: '{{ _("Approve payment") }}'
			}
		)
	});
});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{% if not show_login %}
{{ super() }}
{% endif %}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_vie_de_la_copropriete.html' %}
{% endblock %}

{% block main_content %}
<p>
	<div id="demo">
	<fieldset>
	<legend>{{ _("List of invoices to pay") }}</legend>
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="invoices" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.supplier) }}</th>
				<th>{{ _(fields.invoice_date) }}</th>
				<th>{{ _(fields.invoice) }}</th>
				<th>{{ _(fields.locked_amount) }}</th>
				<th>{{ _(fields.paid_amount) }}</th>
				<th>{{ _(fields.amount) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td colspan="7" class="dataTables_empty">{{ _('Loading data from server') }}</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.supplier) }}</th>
				<th>{{ _(fields.invoice_date) }}</th>
				<th>{{ _(fields.invoice) }}</th>
				<th>{{ _(fields.locked_amount) }}</th>
				<th>{{ _(fields.paid_amount) }}</th>
				<th>{{ _(fields.amount) }}</th>
				<th width="20"></th>
			</tr>
		</tfoot>
	</table>
	</fieldset>
	</div>
	<br /><br />
	<div>
	<fieldset>
	<legend>{{ _("Payments pending approval") }}</legend>
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="payments" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.date) }}</th>
				<th>{{ _(fields.supplier) }}</th>
				<th>{{ _(fields.invoice) }}</th>
				<th>{{ _(fields.amount_ttc) }}</th>
				<th>{{ _(fields.amount) }}</th>
				<th>{{ _(fields.responsible) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td colspan="11" class="dataTables_empty">{{ _("Loading data from server") }}</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.date) }}</th>
				<th>{{ _(fields.supplier) }}</th>
				<th>{{ _(fields.invoice) }}</th>
				<th>{{ _(fields.amount_ttc) }}</th>
				<th>{{ _(fields.amount) }}</th>
				<th>{{ _(fields.responsible) }}</th>
				<th width="20"></th>
			</tr>
		</tfoot>
	</table>
	</fieldset>
	</div>
	
	
	
	{% include "templates/includes_popup_form.html" %}
</p>
<script>
$(function() {
	var user_lang = "{{ app_user.lang }}";
	if (user_lang == "en") { user_lang = "en-GB"};
	$.datepicker.setDefaults( $.datepicker.regional[ user_lang ] );
	
	$("#date").live("focus", function() {
	    $(this).datepicker({
	        inline: true,
	    });
	});
});
</script>			
{% endblock %}
